//
//  GYCharacteristic.h
//  LockManagement
//
//  Created by apple on 2018/7/30.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

@class GYService;
@class GYCharacteristic;
@class GYPeriphreal;

typedef NS_ENUM(NSUInteger , OperationType) {
    operationTypeWrite = 0,
    operationTypeRead,
    operationTypeNotify,
};

/**
 往特征上写数据

 @param characteristic 特征
 @param data 数据
 @param error <#error description#>
 */
typedef void(^blueManagerCharacteristicOperationBlcok)(GYCharacteristic *characteristic, NSData *data, NSError *error);

@interface GYCharacteristic : NSObject

/** 特征的名字 */
@property (nonatomic, strong) NSString *name;

/** 特征唯一ID */
@property (nonatomic,strong)CBUUID *UUID ;

/** 特征 */
@property (nonatomic, strong) CBCharacteristic *characteristic;

/** 特征所属于的服务 */
@property (nonatomic, strong, readonly) GYService *service;

/** 特征所属于的服务 */
@property (nonatomic, strong, readonly) GYPeriphreal *periphreal;

/** 特征上所有的特性 */
@property (nonatomic, assign, readonly) CBCharacteristicProperties properties;
@property (nonatomic,strong,readonly) NSString *propertiesString ;

/** 所包含的数据 */
@property (nonatomic, strong,readonly) NSData *value;

/** 是否在监听数据 */
@property (nonatomic,assign,readonly)BOOL isNotifying ;

//@property(nonatomic, strong) NSMutableArray<EasyDescriptor *> *descriptorArray ;

/**
 * 接收到的数据都在这个数组里面，记录最后5次的操作
 */
@property (nonatomic, strong, readonly) NSMutableArray *readDataArray ;
@property (nonatomic, strong, readonly) NSMutableArray *writeDataArray ;
@property (nonatomic, strong, readonly) NSMutableArray *notifyDataArray ;


/**
 初始化一个特征

 @param character 特征
 @return <#return value description#>
 */
- (instancetype)initWithCharacteristic:(CBCharacteristic *)character ;

/**
 初始化一个特征

 @param character 特征
 @param peripheral 外围设备
 @return <#return value description#>
 */
- (instancetype)initWithCharacteristic:(CBCharacteristic *)character perpheral:(GYPeriphreal *)peripheral ;


/**
 往特征上写数据

 @param byte 字节
 @param callback <#callback description#>
 */
- (void)writeValueWithByte:(int8_t)byte callback:(blueManagerCharacteristicOperationBlcok)callback ;

/**
 往特征上写数据

 @param data 数据是二进制格式
 @param callback <#callback description#>
 */
- (void)writeValueWithData:(NSData *)data callback:(blueManagerCharacteristicOperationBlcok)callback ;

/**
 读取特征上收到的值

 @param callback <#callback description#>
 */
- (void)readValueWithCallback:(blueManagerCharacteristicOperationBlcok)callback ;

/**
 监听服务

 @param value <#value description#>
 @param callback <#callback description#>
 */
- (void)notifyWithValue:(BOOL)value callback:(blueManagerCharacteristicOperationBlcok)callback ;

/**
 操作 外围设备 操作完的回调

 @param type <#type description#>
 @param error <#error description#>
 */
- (void)dealOperationCharacterWithType:(OperationType)type error:(NSError *)error ;

/**
 处理service中搜索到descriper的结果

 @param error <#error description#>
 */
- (void)dealDiscoverDescriptorWithError:(NSError *)error ;

//- (void)discoverDescriptorWithCallback:(blueToothFindDescriptorCallback)callback ;










@end

